﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for ImageDB
/// </summary>
/// 

namespace CE.CXImageDB
{
    public class ImageDB
    {
        public ImageDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public CXImage.Image GetProviderCarImage(String ImageName)
        {
            CXImage.Image _cximage = null;

            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocCXImageSelectSingleItem]";

            SortedList _spara = new SortedList();
            _spara.Add("@ImageName", ImageName);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cximage = new CXImage.Image();
                    _cximage = FillDataRecord(_dt, 0);
                }
            }
            return _cximage;
        }

        private CXImage.Image FillDataRecord(DataTable myDataTable, int RowId)
        {
            CXImage.Image myCarImage = new CXImage.Image();
            myCarImage.ImageId = Convert.ToInt32(myDataTable.Rows[RowId]["ImageId"].ToString());
            myCarImage.ImageName = myDataTable.Rows[RowId]["ImageName"].ToString();
            myCarImage.ImageUrl = myDataTable.Rows[RowId]["ImageUrl"].ToString();
            myCarImage.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());

            return myCarImage;
        }
    }
}
